<?php
//======================================================================================
//
// Function: Get customer dashboard data
//
// Programmer: JKJ
// Date : 2025-05-01
//
// Workers unite...
//
// Copyright Reeft A/S (c) - 2025
//======================================================================================
//======================================================================================
// Set start time
//======================================================================================
$starttime = microtime(true);
//======================================================================================
// General config
//======================================================================================
include "config/config.php";
//======================================================================================
// Get input
//======================================================================================
//======================================================================================
// Get session variables
//======================================================================================
include "include/getsession.php";
include "include/sec2hms.php";
include "include/REEFT_date_convert.php";
//======================================================================================
// Set language
//======================================================================================
include "include/set_language.php";
//======================================================================================
// Set defaults
//======================================================================================
//======================================================================================
// Connect to SQLite database in file
//======================================================================================
$entries_found = 0;
$currentDate = date('Y-m-d');
$currentTime = date('H:i:s');
$returnCode = '00';
$returnMsg = 'Alles ist gut';
// Init
$aryDetail = array();
header('Content-Type: application/json;charset=utf-8');
//======================================================================================
// Set database
//======================================================================================
//$db_name = 'customer/REEFT_integration.sqlite3';
$db_name = $CUSTOMER_DATABASE_PATH;
$DFT_SQLLITE_IP = $db_name;
//======================================================================================
// Check if database file exists
//======================================================================================
if (!file_exists($db_name)) {
die(json_encode(['error' => "Database file '$db_name' does not exist."]));
}
//======================================================================================
// Connect to some DB
//======================================================================================
include "include/db_connect.php";
// echo $DFT_SQLLITE_IP;
// exit;
//======================================================================================
// Create SQL - active records
//======================================================================================
$recordsTotalActive = 0;
$sql = "SELECT count(*) as recordsTotalActive FROM reeft_customer WHERE cust_active = 1";
//echo $sql;
include "include/db_run_sql.php";
foreach( $data as $row )
{
$recordsTotalActive = $row["recordsTotalActive"];
}
// Make integer
$recordsTotalActive = intval( $recordsTotalActive );
// Format it...
$recordsTotalActiveFormat = number_format($recordsTotalActive,0,",",".");
//======================================================================================
// Create SQL - in active records
//======================================================================================
$recordsTotalInactive = 0;
$sql = "SELECT count(*) as recordsTotalInactive FROM reeft_customer WHERE cust_active = 0";
include "include/db_run_sql.php";
foreach( $data as $row )
{
$recordsTotalInactive = $row["recordsTotalInactive"];
}
// Make integer
$recordsTotalInactive = intval( $recordsTotalInactive );
// Format it...
$recordsTotalInactiveFormat = number_format($recordsTotalInactive,0,",",".");
//======================================================================================
// Total records
//======================================================================================
$recordsTotal = 0;
// Make integer
$recordsTotal = $recordsTotalActive + $recordsTotalInactive;
// Format it...
$recordsTotalFormat = number_format($recordsTotal,0,",",".");
//======================================================================================
// Calculate response time
//======================================================================================
$endtime = microtime(true);
$response_time = $endtime - $starttime;
$response_time = number_format($response_time, 6, '.', '');
$response_time_raw = number_format($response_time, 6, '.', '');
$response_time = '(' . $response_time . ' seconds)';
$response_time_raw = $response_time_raw;
//======================================================================================
// Create header
//======================================================================================
$aryHeader = array();
$aryDetail = array();
$aryHeader["rpyCMPNO"] = '';
$aryHeader["rpyCMPNO_Name"] = $rpyCMPNO_Name;
$aryHeader["rpyFile_name"] = 'reeft_customer';
$aryHeader["rpyFile_description"] = 'Customer Dashboard data';
$aryHeader["returnCode"] = $returnCode;
$aryHeader["returnMsg"] = $returnMsg;
$aryHeader["currentDate"] = $currentDate;
$aryHeader["currentTime"] = $currentTime;
$aryHeader["recordsTotalActive"] = $recordsTotalActive;
$aryHeader["recordsTotalActiveFormat"] = $recordsTotalActiveFormat;
$aryHeader["recordsTotalInactive"] = $recordsTotalInactive;
$aryHeader["recordsTotalInactiveFormat"] = $recordsTotalInactiveFormat;
$aryHeader["recordsTotal"] = $recordsTotal;
$aryHeader["recordsTotalFormat"] = $recordsTotalFormat;
$aryHeader["response_sec"] = $response_time;
$aryHeader["response_sec_raw"] = $response_time_raw;
// Create array and prepare for json encoding
$returnJson["header"] = $aryHeader;
//$returnJson["data"] = $aryDetail;
//======================================================================================
// Paint it black
//======================================================================================
echo(json_encode($returnJson));
?>